﻿/******************************************************************************
	Cobalt - utility libraries for building XNA games
	Copyright (C) 2008 Philip Djonov

	This program is free software; you can redistribute it and/or modify it
	under the terms of the GNU General Public License as published by the Free
	Software Foundation; either version 2 of the License, or (at your option)
	any later version.

	This program is distributed in the hope that it will be useful, but
	WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
	or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
	for more details.

	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the
	
		Free Software Foundation, Inc.
		51 Franklin Street, Fifth Floor
		Boston, MA  02110-1301, USA.
******************************************************************************/

using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Cobalt.Framework.UI
{

	public delegate void UiEventHandler( Element sender, IEventRoutingContext context );

	public class Group : Element
	{

		public List<Element> Children { get; private set; }

		public Group( UiContext context )
			: base( context )
		{
			Children = new List<Element>();
		}

		protected internal override void TraverseToRender( ITraversalContext context )
		{
			for( int i = 0; i < Children.Count; i++ )
				context.Traverse( Children[i] );
		}

		public event UiEventHandler PreviewEvent;
		public event UiEventHandler HandleEvent;

		protected internal override void OnPreviewEvent( IEventRoutingContext context )
		{
			if( PreviewEvent != null )
				PreviewEvent( this, context );
		}

		protected internal override void OnHandleEvent( IEventRoutingContext context )
		{
			if( HandleEvent != null )
				HandleEvent( this, context );
		}

	}

}